﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Text.RegularExpressions;

namespace CDHunter
{
    class IdentityCheckBrand : CheckBrand
    {
        public IdentityCheckBrand()
        {
            BrandName = ConfigurationSettings.AppSettings["IdentityBrandName"];
            ProductInfoTestOutPath = ConfigurationSettings.AppSettings["IdentityProductInfoTestOutPath"];
            ProductRankTestOutPath = ConfigurationSettings.AppSettings["IdentityProductRankTestOutPath"];

            VolumeToken1 = "<meta content=\"";
            VolumeToken2 = "\" name=Source>";

            VolumeCount = Convert.ToInt32(ConfigurationSettings.AppSettings["IdentityVolumeCount"]);

            String[] scanningSubCategoryURLs = ConfigurationSettings.AppSettings["IdentitySubCategoryURLs"].Split('|');
            for (int i = 0; i < scanningSubCategoryURLs.Length; i++)
            {
                String[] testingUrl = scanningSubCategoryURLs[i].Split(',');
                if (!String.IsNullOrEmpty(testingUrl[0]) && !String.IsNullOrEmpty(testingUrl[1]))
                    SubCategoryURLDictionary.Add(testingUrl[0].Trim(), testingUrl[1].Trim());
            }

            ProductTitleRegex = new Regex(@"<span class=""header"">([^<]*)</span>");
            ProductTitleRegexGroupNum = Convert.ToInt32(ConfigurationSettings.AppSettings["IdentityProductTitleRegexGroupNum"]);

            ProductURIRegex = new Regex(@"<a href='([^']*)'>([\s]*)<img");
            ProductURIRegexGroupNum = Convert.ToInt32(ConfigurationSettings.AppSettings["IdentityProductURIRegexGroupNum"]);

            ProductIDRegex = new Regex(@"ProductID=([^&]*)&");
            ProductIDRegexGroupNum = Convert.ToInt32(ConfigurationSettings.AppSettings["IdentityProductIDRegexGroupNum"]);
        }
    }
}
